package com.unity.bh3.mapper;

import com.unity.bh3.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

/**
 * 用户Mapper接口
 */
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 根据用户名查询用户
     */
    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(String username);
    
    /**
     * 根据ID查询用户
     */
    @Select("SELECT * FROM user WHERE id = #{id}")
    User findById(Long id);
    
    /**
     * 插入用户
     */
    @Insert("INSERT INTO user(username, password, nickname, exp, diamond, gold, stamina, display_character_id, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{nickname}, #{exp}, #{diamond}, #{gold}, #{stamina}, #{displayCharacterId}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);
    
    /**
     * 更新用户钻石
     */
    @Update("UPDATE user SET diamond = #{diamond}, update_time = NOW() WHERE id = #{id}")
    int updateDiamond(User user);
    
    /**
     * 更新用户金币
     */
    @Update("UPDATE user SET gold = #{gold}, update_time = NOW() WHERE id = #{id}")
    int updateGold(User user);
    
    /**
     * 更新用户体力
     */
    @Update("UPDATE user SET stamina = #{stamina}, update_time = NOW() WHERE id = #{id}")
    int updateStamina(User user);
    
    /**
     * 更新用户信息
     */
    @Update("UPDATE user SET nickname = #{nickname}, display_character_id = #{displayCharacterId}, update_time = NOW() WHERE id = #{id}")
    int updateInfo(User user);
}